import { Injectable } from '@angular/core';
import { Observable } from 'rxjs'
import  axios  from 'axios';
@Injectable({
  providedIn: 'root'
})
export class ViewsserviceService {

  constructor() { }
  getInitWindowWidth(obj):any{
    // 异步封装
    return new Observable ((observer) => {
      var windowSize:number = document.documentElement.clientWidth;
    if(obj.judge === 0) { //当等于0时 用 >=
      if(windowSize >= obj.windowWidth) {
        observer.next(obj.trueValue); // 返回 obj.trueValue
     }else{
       observer.next(obj.flaseValue);
     }
    }else if(obj.judge === 1){ //当等于1代表用 <= 
      if(windowSize <= obj.windowWidth) {
        observer.next(obj.trueValue);
      }else{
        observer.next(obj.flaseValue);
      }
    }
    })
  }
  getDiscussData(url, method, data):any {
    return new Promise((resolve,reject) => {
      axios({
        url,
        method,
        data
      }).then(res => {
        resolve(res)
      })
    })
  }
}
